package com.wisdom.benefit.jufa.widget;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;

import androidx.appcompat.widget.AppCompatButton;

/**
 * 两个字的时候中间加空格
 * Created by zhoudawei on 2017/9/20.
 */

public class WordSpaceButton extends AppCompatButton {

    public WordSpaceButton(Context context) {
        super(context);
    }

    public WordSpaceButton(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public WordSpaceButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        if (getText().toString().length() == 2) {
            String textOriginal = getText().toString();
            String text = textOriginal.charAt(0) + " " + textOriginal.charAt(1);
            setText(text);
        } else {
            super.onDraw(canvas);
        }
    }
}
